home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Interfaces&Libraries / Universal / Interfaces / CIncludes / GXMath.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-17  |  8.8 KB  |  315 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        GXMath.h
  3.  
  4.      Contains:    QuickDraw GX math routine interfaces.
  5.  
  6.      Version:    Technology:    Quickdraw GX 1.1
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1994-1998 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __GXMATH__
  18. #define __GXMATH__
  19.  
  20. #ifndef __CONDITIONALMACROS__
  21. #include <ConditionalMacros.h>
  22. #endif
  23. #ifndef __MACTYPES__
  24. #include <MacTypes.h>
  25. #endif
  26. #ifndef __FIXMATH__
  27. #include <FixMath.h>
  28. #endif
  29.  
  30.  
  31.  
  32. #if PRAGMA_ONCE
  33. #pragma once
  34. #endif
  35.  
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39.  
  40. #if PRAGMA_IMPORT
  41. #pragma import on
  42. #endif
  43.  
  44. #if PRAGMA_STRUCT_ALIGN
  45.     #pragma options align=mac68k
  46. #elif PRAGMA_STRUCT_PACKPUSH
  47.     #pragma pack(push, 2)
  48. #elif PRAGMA_STRUCT_PACK
  49.     #pragma pack(2)
  50. #endif
  51.  
  52. #if defined(__MWERKS__) && TARGET_CPU_68K
  53.     #pragma push
  54.     #pragma pointers_in_D0
  55. #endif
  56.  
  57.  
  58.  
  59. struct gxPoint {
  60.     Fixed                             x;
  61.     Fixed                             y;
  62. };
  63. typedef struct gxPoint                    gxPoint;
  64.  
  65. typedef unsigned short                     gxColorValue;
  66.  
  67. struct gxPolar {
  68.     Fixed                             radius;
  69.     Fixed                             angle;
  70. };
  71. typedef struct gxPolar                    gxPolar;
  72.  
  73. struct gxMapping {
  74.     Fixed                             map[3][3];
  75. };
  76. typedef struct gxMapping                gxMapping;
  77.  
  78. #define    gxColorValue1            ((gxColorValue) 0x0000FFFF)
  79. #define  gxPositiveInfinity        ((long) 0x7FFFFFFFL)
  80. #define    gxNegativeInfinity        ((long) 0x80000000L)
  81.  
  82. EXTERN_API_C( gxMapping *)
  83. CopyToMapping                    (gxMapping *            target,
  84.                                  const gxMapping *        source)                                THREEWORDINLINE(0x303C, 0x0031, 0xA832);
  85.  
  86. EXTERN_API_C( gxMapping *)
  87. InvertMapping                    (gxMapping *            target,
  88.                                  const gxMapping *        source)                                THREEWORDINLINE(0x303C, 0x0032, 0xA832);
  89.  
  90. EXTERN_API_C( gxMapping *)
  91. MapMapping                        (gxMapping *            target,
  92.                                  const gxMapping *        source)                                THREEWORDINLINE(0x303C, 0x0033, 0xA832);
  93.  
  94. EXTERN_API_C( gxMapping *)
  95. MoveMapping                        (gxMapping *            target,
  96.                                  Fixed                     hOffset,
  97.                                  Fixed                     vOffset)                            THREEWORDINLINE(0x303C, 0x0034, 0xA832);
  98.  
  99. EXTERN_API_C( gxMapping *)
  100. MoveMappingTo                    (gxMapping *            target,
  101.                                  Fixed                     hPosition,
  102.                                  Fixed                     vPosition)                            THREEWORDINLINE(0x303C, 0x0035, 0xA832);
  103.  
  104. EXTERN_API_C( gxMapping *)
  105. NormalizeMapping                (gxMapping *            target)                                THREEWORDINLINE(0x303C, 0x0036, 0xA832);
  106.  
  107. EXTERN_API_C( gxMapping *)
  108. RotateMapping                    (gxMapping *            target,
  109.                                  Fixed                     angle,
  110.                                  Fixed                     xCenter,
  111.                                  Fixed                     yCenter)                            THREEWORDINLINE(0x303C, 0x0037, 0xA832);
  112.  
  113. EXTERN_API_C( gxMapping *)
  114. ScaleMapping                    (gxMapping *            target,
  115.                                  Fixed                     hFactor,
  116.                                  Fixed                     vFactor,
  117.                                  Fixed                     xCenter,
  118.                                  Fixed                     yCenter)                            THREEWORDINLINE(0x303C, 0x0038, 0xA832);
  119.  
  120. EXTERN_API_C( gxMapping *)
  121. ResetMapping                    (gxMapping *            target)                                THREEWORDINLINE(0x303C, 0x0039, 0xA832);
  122.  
  123. EXTERN_API_C( gxMapping *)
  124. SkewMapping                        (gxMapping *            target,
  125.                                  Fixed                     skewX,
  126.                                  Fixed                     skewY,
  127.                                  Fixed                     xCenter,
  128.                                  Fixed                     yCenter)                            THREEWORDINLINE(0x303C, 0x003A, 0xA832);
  129.  
  130. EXTERN_API_C( void )
  131. MapPoints                        (const gxMapping *        source,
  132.                                  long                     count,
  133.                                  gxPoint                 vector[])                                THREEWORDINLINE(0x303C, 0x003B, 0xA832);
  134.  
  135. EXTERN_API_C( short )
  136. FirstBit                        (unsigned long             x)                                    THREEWORDINLINE(0x303C, 0x003C, 0xA832);
  137.  
  138. EXTERN_API_C( short )
  139. WideScale                        (const wide *            source)                                THREEWORDINLINE(0x303C, 0x003D, 0xA832);
  140.  
  141. EXTERN_API_C( short )
  142. LinearRoot                        (Fixed                     first,
  143.                                  Fixed                     last,
  144.                                  Fract                     t[])                                    THREEWORDINLINE(0x303C, 0x003E, 0xA832);
  145.  
  146. EXTERN_API_C( short )
  147. QuadraticRoot                    (Fixed                     first,
  148.                                  Fixed                     control,
  149.                                  Fixed                     last,
  150.                                  Fract                     t[])                                    THREEWORDINLINE(0x303C, 0x003F, 0xA832);
  151.  
  152. EXTERN_API_C( gxPoint *)
  153. PolarToPoint                    (const gxPolar *        ra,
  154.                                  gxPoint *                xy)                                    THREEWORDINLINE(0x303C, 0x0040, 0xA832);
  155.  
  156. EXTERN_API_C( gxPolar *)
  157. PointToPolar                    (const gxPoint *        xy,
  158.                                  gxPolar *                ra)                                    THREEWORDINLINE(0x303C, 0x0041, 0xA832);
  159.  
  160. EXTERN_API_C( Fract )
  161. FractCubeRoot                    (Fract                     source)                                THREEWORDINLINE(0x303C, 0x0042, 0xA832);
  162.  
  163. EXTERN_API_C( Fract )
  164. FractDivide                        (Fract                     dividend,
  165.                                  Fract                     divisor)                            THREEWORDINLINE(0x303C, 0x0043, 0xA832);
  166.  
  167. EXTERN_API_C( Fract )
  168. FractMultiply                    (Fract                     multiplicand,
  169.                                  Fract                     multiplier)                            THREEWORDINLINE(0x303C, 0x0044, 0xA832);
  170.  
  171. EXTERN_API_C( Fract )
  172. FractSineCosine                    (Fixed                     degrees,
  173.                                  Fract *                cosine)                                THREEWORDINLINE(0x303C, 0x0045, 0xA832);
  174.  
  175. EXTERN_API_C( Fract )
  176. FractSquareRoot                    (Fract                     source)                                THREEWORDINLINE(0x303C, 0x0046, 0xA832);
  177.  
  178. EXTERN_API_C( Fixed )
  179. FixedDivide                        (Fixed                     dividend,
  180.                                  Fixed                     divisor)                            THREEWORDINLINE(0x303C, 0x0047, 0xA832);
  181.  
  182. EXTERN_API_C( Fixed )
  183. FixedMultiply                    (Fixed                     multiplicand,
  184.                                  Fixed                     multiplier)                            THREEWORDINLINE(0x303C, 0x0048, 0xA832);
  185.  
  186. /* This next call is (source * multiplier / divisor) -- it avoids underflow, overflow by using wides */
  187. EXTERN_API_C( long )
  188. MultiplyDivide                    (long                     source,
  189.                                  long                     multiplier,
  190.                                  long                     divisor)                            THREEWORDINLINE(0x303C, 0x0049, 0xA832);
  191.  
  192. EXTERN_API_C( unsigned long )
  193. Magnitude                        (long                     deltaX,
  194.                                  long                     deltaY)                                THREEWORDINLINE(0x303C, 0x004A, 0xA832);
  195.  
  196. EXTERN_API_C( long )
  197. VectorMultiplyDivide            (long                     count,
  198.                                  const long *            vector1,
  199.                                  long                     step1,
  200.                                  const long *            vector2,
  201.                                  long                     step2,
  202.                                  long                     divisor)                            THREEWORDINLINE(0x303C, 0x004B, 0xA832);
  203.  
  204.  
  205.  
  206.  
  207. /* wide operations are defined within FixMath.h only for PowerPC */
  208. #if !TARGET_CPU_PPC
  209. EXTERN_API_C( wide *)
  210. WideAdd                            (wide *                    target,
  211.                                  const wide *            source)                                THREEWORDINLINE(0x303C, 0x004C, 0xA832);
  212.  
  213. EXTERN_API_C( short )
  214. WideCompare                        (const wide *            target,
  215.                                  const wide *            source)                                THREEWORDINLINE(0x303C, 0x004D, 0xA832);
  216.  
  217. EXTERN_API_C( wide *)
  218. WideNegate                        (wide *                    target)                                THREEWORDINLINE(0x303C, 0x004E, 0xA832);
  219.  
  220. EXTERN_API_C( wide *)
  221. WideShift                        (wide *                    target,
  222.                                  long                     shift)                                THREEWORDINLINE(0x303C, 0x004F, 0xA832);
  223.  
  224. EXTERN_API_C( unsigned long )
  225. WideSquareRoot                    (const wide *            source)                                THREEWORDINLINE(0x303C, 0x0050, 0xA832);
  226.  
  227. EXTERN_API_C( wide *)
  228. WideSubtract                    (wide *                    target,
  229.                                  const wide *            source)                                THREEWORDINLINE(0x303C, 0x0051, 0xA832);
  230.  
  231. EXTERN_API_C( wide *)
  232. WideMultiply                    (long                     multiplicand,
  233.                                  long                     multiplier,
  234.                                  wide *                    target)                                THREEWORDINLINE(0x303C, 0x0052, 0xA832);
  235.  
  236. /* returns the quotient */
  237. EXTERN_API_C( long )
  238. WideDivide                        (const wide *            dividend,
  239.                                  long                     divisor,
  240.                                  long *                    remainder)                            THREEWORDINLINE(0x303C, 0x0053, 0xA832);
  241.  
  242. /* quotient replaces dividend */
  243. EXTERN_API_C( wide *)
  244. WideWideDivide                    (wide *                    dividend,
  245.                                  long                     divisor,
  246.                                  long *                    remainder)                            THREEWORDINLINE(0x303C, 0x0055, 0xA832);
  247.  
  248. #endif  /* !TARGET_CPU_PPC */
  249.  
  250.  
  251.  
  252. EXTERN_API_C( wide *)
  253. VectorMultiply                    (long                     count,
  254.                                  const long *            vector1,
  255.                                  long                     step1,
  256.                                  const long *            vector2,
  257.                                  long                     step2,
  258.                                  wide *                    dot)                                THREEWORDINLINE(0x303C, 0x0054, 0xA832);
  259.  
  260. EXTERN_API_C( unsigned long )
  261. RandomBits                        (long                     count,
  262.                                  long                     focus)                                THREEWORDINLINE(0x303C, 0x0056, 0xA832);
  263.  
  264. EXTERN_API_C( void )
  265. SetRandomSeed                    (const wide *            seed)                                THREEWORDINLINE(0x303C, 0x0057, 0xA832);
  266.  
  267. EXTERN_API_C( wide *)
  268. GetRandomSeed                    (wide *                    seed)                                THREEWORDINLINE(0x303C, 0x0058, 0xA832);
  269.  
  270.  
  271. #define FixedRound(a)        ((short)((Fixed)(a) + fixed1/2 >> 16))
  272. #define FixedSquareRoot(a)    ((Fixed)FractSquareRoot(a) + 64 >> 7)
  273. #define FixedTruncate(a)        ((short)((Fixed)(a) >> 16))
  274. #define FixedToFract(a)        ((Fract)(a) << 14)
  275. #define FractToFixed(a)        ((Fixed)(a) + 8192L >> 14)
  276. #define FixedToInt(a)       ((short)((Fixed)(a) + fixed1/2 >> 16))
  277. #define IntToFixed(a)       ((Fixed)(a) << 16)
  278. #define FixedToFloat(a)     ((float)(a) / fixed1)
  279. #define FloatToFixed(a)         ((Fixed)((float)(a) * fixed1))
  280. #define FractToFloat(a)     ((float)(a) / fract1)
  281. #define FloatToFract(a)     ((Fract)((float)(a) * fract1))
  282. #define ColorToFract(a)     (((Fract) (a) << 14) + ((Fract)(a) + 2 >> 2))
  283. #define FractToColor(a)     ((gxColorValue) ((a) - ((a) >> 16) + 8191 >> 14))
  284. #ifndef ff    /* ff is already defined on some platforms */
  285. #define ff(a)               IntToFixed(a)
  286. #define fl(a)               FloatToFixed(a)
  287. #endif
  288.  
  289.  
  290. #if defined(__MWERKS__) && TARGET_CPU_68K
  291.     #pragma pop
  292. #endif
  293.  
  294.  
  295. #if PRAGMA_STRUCT_ALIGN
  296.     #pragma options align=reset
  297. #elif PRAGMA_STRUCT_PACKPUSH
  298.     #pragma pack(pop)
  299. #elif PRAGMA_STRUCT_PACK
  300.     #pragma pack()
  301. #endif
  302.  
  303. #ifdef PRAGMA_IMPORT_OFF
  304. #pragma import off
  305. #elif PRAGMA_IMPORT
  306. #pragma import reset
  307. #endif
  308.  
  309. #ifdef __cplusplus
  310. }
  311. #endif
  312.  
  313. #endif /* __GXMATH__ */
  314.  
  315.